#include"RunQueue.hpp"
void* Consumer(void* arg)
{
   //RunQueue<int>* rq = (RunQueue<int>*)arg;
   RunQueue<Task>* rq = (RunQueue<Task>*)arg;
   while(true)
   {
     int x,y;
     Task t;
     rq->Pop(t);
     std::cout<<"Consumer done:"<<t.x<<"+"<<t.y<<"="<<t.run()<<std::endl;
     sleep(1);
   }
}
void* Product(void* arg)
{
   //RunQueue<int>* rq = (RunQueue<int>*)arg;
   RunQueue<Task>* rq = (RunQueue<Task>*)arg;
   while(true)
   {
     int x = rand() % 10 + 1;
     int y = rand() % 100 + 1;
     Task t(x,y);
     rq->Push(t);
     std::cout<<"Product done:"<<x<<"+"<<y<<"=?"<<std::endl;
   }
}
int main()
{
  RunQueue<int> *rq = new RunQueue<int>;
  
  pthread_t c,p;
  pthread_create(&c,nullptr,Consumer,rq);
  pthread_create(&c,nullptr,Product,rq);
   
  pthread_join(c,nullptr);
  pthread_join(p,nullptr);
  delete rq;
  return 0;
}
